const computedBehavior = require('miniprogram-computed').behavior

Page({
  behaviors: [computedBehavior],
  data: {
    profile: {
      avatarUrl: '/static/avatar.png',
      nickName: '千里封冰'
    },
    firstName: '吕',
    lastName: '布'
  },
  computed: {
    fullName(data) {
      return data.firstName + data.lastName
    }
  },
  chooseAvatar(e) {
    /* this.setData({
      profile: {
        ...this.data.profile,
        avatarUrl: e.detail.avatarUrl
      }
    }) */

    this.setData({
      'profile.avatarUrl': e.detail.avatarUrl
    })

    wx.uploadFile({
      filePath: e.detail.avatarUrl,
      name: 'avatar',
      url: 'http://ajax-api.itheima.net/api/file',
      success(r) {
        console.log(r)
      }
    })
  },
  getNickname(e) {
    if (e.detail.value !== this.data.profile.nickName) {
      this.setData({
        'profile.nickName': e.detail.value
      })
    }
  },
  goDemo() {
    wx.navigateTo({
      url: '/pages/demo/demo?name=lb&age=18',
    })
  },
  goDemoRedirect() {
    wx.redirectTo({
      url: '/pages/demo/demo?name=lb&age=18',
    })
  },
  onUnload() {
    console.log('当前页面卸载的时候触发')
  }
})